According to the model selection the best model structure is: y ~ x1 + x2 + x4 + error. Now we’re going to test the model further.

Fit the model

Construct X matrix

Split into train-test

Fit model, generate predictions, compute error (SSE, MSE) and adjusted R^2.

## MSE is: 0.01069316 
## Adjusted R^2 is: 0.9999891

Residual analysis

Numerical analysis

## Residual analysis:
##          Min          25%       Median          75%          Max 
## -0.305319926 -0.061646247  0.008535535  0.077296305  0.291481680
## 
## Residual mean: 0.007
## 
## Residual mode: 0.013

Parameter covariance matrix

##          [,1]     [,2]   [,3]
## [1,]  5.1e-05  1.0e-05 -2e-06
## [2,]  1.0e-05  4.5e-05 -5e-06
## [3,] -2.0e-06 -5.0e-06  1e-06

Parameter uncertainty pdf

Because we have 3 parameters, we’ll need to plot all their combinations resulting in 3 plots.

First we create grid of possible parameter values for which we estimate the uncertainty.

Now we can calculate the pdf

Parameters x1 and x2

Parameters x1 and x4

Parameters x2 and x4

Model’s prediction

Now we’ll generate predictions on training data and 95% confidence intervals

Plot the predictions + CI

Model validation

Validate the model on new train-test split - 70:30

Construct X matrices (train and test)

Re-use the fitting function from model selection

Fit model on training data and predict testing data

## MSE on training data =  0.01094003 
## MSE on testing  data =  0.008348671

Validate model with k-fold cross-validation